package com.example.jobback.util;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;

/**
 * @ClassName: SMSUtil
 * @Description: 阿里云短信服务工具类
 * @Author: lhb
 * @Date: 2025/5/10
 */

public class SMSUtil {
    public static SendSmsResponse sendMessage(String signName, String templateCode, String phoneNumbers, String param, String accessKeyId, String secret) throws ClientException {

        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou",accessKeyId,secret);

        IAcsClient client = new DefaultAcsClient(profile);

        SendSmsRequest request = new SendSmsRequest();

        request.setSysRegionId("cn-hangzhou");
//	    要发送给那个人的电话号码
        request.setPhoneNumbers(phoneNumbers);
//      我们在阿里云设置的签名
        request.setSignName(signName);
//	    我们在阿里云设置的模板
        request.setTemplateCode(templateCode);
//	    在设置模板的时候有一个占位符
        request.setTemplateParam("{\"code\":\""+param+"\"}");

        return client.getAcsResponse(request);
    }
}
